/**
 * 业务对象维护
 * @author miaoyl
 * @date 2018/01/04
 */
define(function () {

    var self,
        doc = document,
        app = win.app,
        layui = win.layui,
        table,
        table_where = {

        },
        cols = [[
            // {field: 'ROW_ID', width: 60, title: '序号'},
            {field: 'CUSTOM_OBJ', width: 120, title: '业务对象编码', fixed: 'left',sort: true, search:'default'}
            , {field: 'CUSTOM_OBJ_NAME_CN', width: 120, title: '业务对象中文名称', sort: true}
            , {field: 'CUSTOM_OBJ_NAME_TW', width: 120, title: '业务对象繁体名称'}
            , {field: 'CUSTOM_OBJ_NAME_EN', width: 120, title: '业务对象英文名称'}
            ,{field: 'CUSTOM_REMARK', width: 137, title: '描述'}
            ,{field: 'CREATE_BY', width: 137, title: '创建人'}
            ,{field: 'CREATE_DATE', width: 137, title: '创建时间'},
            //,{field: 'UPDATE_BY', width: 137, title: '修改人'}
            //,{field: 'UPDATE_DATE', width: 137, title: '修改时间'},
            {
                width: 60,
                title: '',
                toolbar: '#script-customssetting',
                fixed: 'right',
                align: 'center',
                unresize: true
            }
        ]],
        customsSettingAction
    ;

    var Customs = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _tag: 'customs',
                _searchs: [{
                    id: 'customs', tableId: 'customs_table', datas: cols[0]
                }],
                _loadTplsFull: [{
                    dom: 'customs_edit', tpl: 'system/customs_edit'
                }]
            }, win);
        },

        initTable: function () {
            layui.use(['table'], function () {
                table = layui.table;
                table.render({
                    elem: app.getByid(doc, 'customs_table'),
                    url: g_ctxPath + 'sys/businessObject/getCustomslist',
                    exportsUrl: g_ctxPath + 'sys/businessObject/getCustomslist',
                    exportsName: '业务对象数据',
                    title: '业务对象信息表',
                    id: 'customs_table',
                    toolbar: '#table-toolbar',
                    defaultToolbar: ['filter'], //, 'exports'
                    height: 'full',
                    cols: cols,
                    page: true,
                    where: table_where
                });

                layui.laytpl(app.getByid(doc, 'script-customssetting-action').innerHTML).render({}, function (string) {
                    customsSettingAction = string;
                });

                var tipsIndex = null;

                table.on('tool(customs_table)', function (obj) {

                    layer.tips(customsSettingAction, obj.td, {
                        tips: [3, '']
                        , time: 5000
                        , anim: 500
                        , maxWidth: 120
                        , skin: 'layui-table-tips'
                        , success: function (layero, index) {
                            layero.find('li').on('click', function () {
                                switch ($(this).attr('inx')) {
                                    case '0':
                                        self._openTplFull({
                                            tag: 'customs_edit',
                                            tagData: obj,
                                            index: 0,
                                            openOpts:{
                                                maxmin: true
                                            }
                                        });
                                        break;
                                    case '1':
                                        self.delCustoms(obj);
                                        break;
                                }
                                layer.close(index);
                            });
                        }
                    });
                });

                //监听行双击事件
                table.on('rowDouble(customs_table)', function (obj) {
                    self._openTplFull({
                        tag: 'customs_edit',
                        tagData: obj,
                        index: 0,
                        openOpts: {
                            title: '业务对象信息编辑',
                            maxmin: true
                        }
                    });
                });

                //监听事件
                table.on('toolbar(customs_table)', function (obj) {
                    switch (obj.event) {
                        case 'add':
                            self._openTplFull({
                                tag: 'customs_edit',
                                tagData: {
                                    is_add: true
                                },
                                index: 0
                            });
                            break;
                    }
                });

                $(doc).on('click', function () {
                    tipsIndex && layer.close(tipsIndex);
                });

            });
        },

        reloadTableCurr: function () {
            self._reloadTable({id: 'customs_table', where: table_where});
        },

        delCustoms: function (obj) {
            app.confirm({
                msg: '是否删除选择的信息？',
                ok: function () {
                    app.ajax({
                        xurl: 'sys/businessObject/del',
                        xdata: obj.data,
                        loading: true,
                        okmsg: '业务对象信息删除成功',
                        cb: function (result) {
                            if (result.ok) {
                                self.reloadTableCurr();
                            }
                        }
                    });
                }
            });

        },

        _ready: function () {
            this._super({
                vue: [{
                    el: '#page',
                    data: '',
                    searchId: 'customs',
                    methods: {}
                }]
            });

            self.initTable();
        },
        _lazy: function () {
            this._super();
        }
    });

    return new Customs();

});